<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./promise原理.js"></script>

</head>

<body>
  <h1>自己实现的promise</h1>

</body>

<script>
  // 原生Promise
  let p1 = new Promise((resolve, reject) => {
    resolve('console')
  })

  console.log('原生', p1);
  p1.then(res => {
    console.log('原生', res);
  }, err => {
    console.log('原生', err);

  })



  // promise的三种对象状态，pending fulfilled, rejected
  let p = new KPromise((resolve, reject) => {
    resolve('console')
  });

  console.log(p);

  // promise对象有then方法，链式调用
  // 会接受两个参数，onResolved, onRejected
  p.then(res => {
    console.log(res);
  }, err => {
    console.log(err);

  })


</script>

</html>